<? include "../connect.php"; ?>
<?php
ob_start();
session_start();
include "checksession.php";
date_default_timezone_set('Asia/Bangkok');

$emp_id=$_GET['emp_id'];
?>

<?
require('fpdf.php');
define('FPDF_FONTPATH','font/');

$test = $_GET['emp_id'];
class PDF extends FPDF{

	function conv($string){
	return iconv('UTF-8', 'TIS-620', $string);
	}

	function Header(){

			$this->AddFont('eucro','','eucro.php');
			$this->AddFont('eucrob','B','eucrob.php');
			$this->SetFont('eucro','',14);
			$this->SetFont('eucrob','B',20);
			$this->Cell(270,5,iconv('UTF-8','TIS-620','บัญชีรายชื่อสารเคมี'),0,0,'C');
			$this->SetFont('eucrob','B',16);
			$this->Text(250,5,iconv( 'UTF-8','TIS-620',"F-IT-006  R00"),0,1,"R");
			$this->Text(250,25,iconv( 'UTF-8','TIS-620',"หน้า ").$this->PageNo(),0,0,'R');
			$this->Ln(20);
			$this->SetFillColor(255,255,255);
			$this->SetLineWidth(.3);
			$header=array('ลำดับที่','รายชื่อสารเคมี','คุณสมบัติ','สถานที่จัดเก็บ','การใช้งาน','หมายเหตุ');
			$w=array(15,65,40,40,100,20);
			for($i=0;$i<count($header);$i++){
				//$this->Cell($w[$i],7,$header[$i],1,0,'C',true);
				$this->Cell($w[$i],7,iconv('UTF-8', 'TIS-620', $header[$i]),1,0,'C',true);
			}
			$this->Ln();

		}
	
	function Footer(){
		
		$this->SetY(-15);
		$this->Cell(50,0,iconv( 'UTF-8','TIS-620',"......................................"),0,0,'C');
		$this->Cell(67,0,iconv( 'UTF-8','TIS-620',"........./........./................."),0,0,'L');
		$this->Cell(110,0,iconv( 'UTF-8','TIS-620',".........................................."),0,0,'R');
		$this->Cell(50,0,iconv( 'UTF-8','TIS-620',"........./........./................."),0,1,'C');
		$this->Cell(50,15,iconv( 'UTF-8','TIS-620',"ผู้จัดทำ"),0,0,'C');
		$this->Cell(160,15,iconv( 'UTF-8','TIS-620',"ผู้อนุมัติ"),0,0,'R');
		
		}
	
	function FancyTable($header,$data)
	{

	//Colors, line width and bold font
	$this->SetLineWidth(.3);
	$this->SetFillColor(255,255,255);
	$this->SetFont('','B');
	//Header
	$w=array(15,65,40,40,100,20);

	//Color and font restoration
	$this->SetTextColor(0);
	$this->SetFont('eucro','',16);

	//Data
	$fill=false;
	$i=1;
	$nb = 37;
	for($i=1;$i<=21;$i++)
	{	
		
		$this->Cell($w[0],7,'',1,0,'C',$fill);
		$this->Cell($w[1],7,'',1,0,'C',$fill);
		$this->Cell($w[2],7,'',1,0,'C',$fill);
		$this->Cell($w[3],7,'',1,0,'C',$fill);
		$this->Cell($w[4],7,'',1,0,'C',$fill);
		$this->Cell($w[5],7,'',1,0,'C',$fill);
		
		//$i++;
		$this->Ln();
		$fill=!$fill;
	

	}
	$i=1;
	
	foreach($data as $row)
	{	
		$this->SetXY(10,$nb);
		$this->Cell($w[0],7,$i,1,0,'C',$fill);
		$this->Cell($w[1],7,$row['che_name'],1,0,'L',$fill);
		$this->Cell($w[2],7,$row['che_attribute'],1,0,'L',$fill);
		$this->Cell($w[3],7,$row['che_location'],1,0,'L',$fill);
		$this->Cell($w[4],7,$row['che_work'],1,0,'L',$fill);
		$this->Cell($w[5],7,$row['che_note'],1,0,'L',$fill);
		
		$i++;
		$nb=$nb+7;
		$this->Ln(1);
		$fill=!$fill;

	}

}
}
$pdf=new PDF();
//*** Load MySQL Data ***//
include "../connect.php";
//แก้database รายชื่อสารเคมี
$strSQL = "SELECT * FROM chemical order by che_id asc ";
$objQuery = mysql_query($strSQL);
mysql_query("set NAMES'TIS620'");
$resultData = array();
for ($i=0;$i<mysql_num_rows($objQuery);$i++) {
	$result = mysql_fetch_array($objQuery);
	
	$result['che_name'] = iconv("UTF-8", "ISO-8859-11",$result['che_name']);
	$result['che_attribute'] = iconv("UTF-8", "ISO-8859-11",$result['che_attribute']);
	$result['che_location'] = iconv("UTF-8", "ISO-8859-11",$result['che_location']);
	$result['che_work'] = iconv("UTF-8", "ISO-8859-11",$result['che_work']);
	$result['che_note'] = iconv("UTF-8", "ISO-8859-11",$result['che_note']);

	array_push($resultData,$result);

}
//************************//
$pdf->AddPage('L','A4');
$pdf->SetAutoPageBreak(true , 20);
$pdf->FancyTable($header,$resultData);
$pdf->Output();
?>